package com.epam.cdp.jpa.dao;

import java.io.Serializable;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;

import com.epam.cdp.jpa.model.BaseEntity;

/**
 * This class has injected EXTENDED entity manger in order to keep it opened between methods invocations.
 * Such approach allows use lazy loading mechanism provided by JPA (without any additional custom services).
 * 
 * Classes that will extend this class should be statefull EJB.
 * 
 * @author igor
 *
 * @param <T>
 */
public abstract class AbstractStatefullDAO<T extends BaseEntity> extends AbstractGenericDAO<T> implements Serializable {

    private static final long serialVersionUID = 1L;
    
    @PersistenceContext(unitName = "cdp_jpa_unit", type = PersistenceContextType.EXTENDED)
    private EntityManager em;
    
    @Override
    public EntityManager getEntityManager() {
	return em;
    }

}
